<template>
  <div>
    <!--    表格信息-->
    <div class="main-concat">
      <el-table :data="list" border style="width: 98%;margin: 0 auto">
        <el-table-column align="center" label="Id" width="60">
          <template slot-scope="scope">
            {{ scope.row.id }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="地址" width="280">
          <template slot-scope="scope">
            {{ scope.row.address }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="联系电话" width="160">
          <template slot-scope="scope">
            {{ scope.row.phone }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="联系邮箱" width="160">
          <template slot-scope="scope">
            <div v-if="scope.row.e_mail">
              {{ scope.row.e_mail }}
            </div>
            <div v-else>
              <el-tag type="warning">暂无邮箱</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="更新时间" width="160">
          <template slot-scope="scope">
            {{ scope.row.updated_at }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="图片" width="160">
          <template slot-scope="scope">
            <img :src="scope.row.w_code" alt="图片丢失"/>
          </template>
        </el-table-column>
        <el-table-column align="center" header-align="center" label="操作">
          <template slot-scope="scope">
            <el-button plainsize="mini" type="primary" @click="changeConcat(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--    修改信息  -->
    <el-dialog :visible.sync="dialogVisibleChange" title="修改信息" width="60%">
      <el-form ref="getForm" v-model="getForm" label-width="80px">
        <el-form-item label="地址">
          <el-input v-model="getForm.address"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="getForm.emial"></el-input>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="getForm.phone"></el-input>
        </el-form-item>
        <el-form-item label="图片地址">
          <img :src="getForm.w_code" alt=""/>
          <Upload></Upload>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleChange = false">取消</el-button>
        <el-button type="primary" @click="confirmChange(getForm)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { c, xg } from '@/api/concat'
import { Message } from "element-ui";

export default {
  name: "Concat",
  data () {
    return {
      list: null,
      getForm: [],
      dialogVisible: true,
      dialogVisibleChange: false,
      activeName: 'second'
    }
  },
  created () {
    this.fetchData ()
  },
  methods: {
    //  获取数据
    async fetchData () {
      await c ().then (( response ) => {
        const {id, address, updated_at, phone, email, wCode} = response.data
        this.list = [{address: address, updated_at: updated_at, e_mail: email, id: id, phone: phone, w_code: wCode}]
      })
    },
    // 修改联系我们
    changeConcat ( row ) {
      this.$store.commit ('upload/CLEAR_IMG')
      this.getForm = row
      this.dialogVisibleChange = true
    },
    confirmChange ( data ) {
      console.log (data)
      const imgUrl = data.w_code
      if (this.$store.state.upload.imgUrl == null || this.$store.state.upload.imgUrl === '') {
        this.getForm.w_code = imgUrl
        xg (data).then (( response ) => {
          if (response.code === 200) {
            this.dialogVisibleChange = false
            Message.success ({
              message: '修改成功'
            })
          }
        })
      } else {
        this.getForm.w_code = this.$store.state.upload.imgUrl
        xg (data).then (( response ) => {
          if (response.code === 200) {
            this.dialogVisibleChange = false
            Message.success ({
              message: '修改成功'
            })
          }
        })
      }
    }
  }
}
</script>

<style scoped>


</style>
